# -*- coding: utf-8 -*-
# @Author    : Tian Wencheng
# @CreateTime: 2021/1/15 16:22
# @FileName  : detection_setting.py
# @IDE       : PyCharm
# @Git       : https://gitee.com/dianetian/projects


from common.request import HTTPRequest
from interface.base import BaseModule


class DetectionSettingModule(BaseModule):
    def __init__(self):
        self.request_url = ""
        self.request_method = ""
        self.request_headers = {"Content-Type": "application/json"}
        self.request_params = None
        self.cookies = super().cookies
        self.web_url = super().web_url

    def add_camera_event_detection(self, **kwargs):
        camera_id = kwargs.get("cameraId")
        event_type_id = kwargs.get("eventTypeId")
        form_data = kwargs.get("formData")

        self.request_url = "/api/manager/areaDetection/V2"
        url = self.web_url + self.request_url
        self.request_method = "POST"
        self.request_params = {"cameraId": camera_id, "eventTypeId": event_type_id, "formData": form_data}

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response

    def update_camera_event_detection(self, **kwargs):
        id = kwargs.get("id")
        camera_id = kwargs.get("cameraId")
        event_type_id = kwargs.get("eventTypeId")
        form_data = kwargs.get("formData")

        self.request_url = "/api/manager/areaDetection/V2"
        url = self.web_url + self.request_url
        self.request_method = "POST"
        self.request_params = {"id": id, "cameraId": camera_id, "eventTypeId": event_type_id, "formData": form_data}

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response

    def delete_camera_event_detection(self, **kwargs):
        ids = kwargs.get("ids")

        self.request_url = "/api/manager/areaDetection/V2"
        url = self.web_url + self.request_url
        self.request_method = "DELETE"
        self.request_params = {"ids": ids}

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response

    def get_camera_event_detection_list(self, **kwargs):
        event_type_id = kwargs.get("eventTypeId")
        camera_ids = kwargs.get("cameraIds")
        current_page = kwargs.get("currentPage")
        page_size = kwargs.get("pageSize")

        self.request_url = "/api/manager/areaDetection/list/V2"
        url = self.web_url + self.request_url
        self.request_method = "GET"
        self.request_params = {"eventTypeId": event_type_id, "cameraIds": camera_ids, "currentPage": current_page,
                               "pageSize": page_size}

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response

    def get_camera_usable_event_type(self, **kwargs):
        camera_id = kwargs.get("cameraId")

        self.request_url = "/api/manager/detectionType/V2"
        url = self.web_url + self.request_url
        self.request_method = "GET"
        self.request_params = {"cameraId": camera_id}

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response

    def get_camera_event_detection(self, **kwargs):
        id = kwargs.get("id")

        self.request_url = "/api/manager/areaDetection/findById/V2"
        url = self.web_url + self.request_url
        self.request_method = "GET"
        self.request_params = {"id": id}

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response

    def get_camera_pixel(self, **kwargs):
        id = kwargs.get("id")

        self.request_url = "/api/getEncodePara"
        url = self.web_url + self.request_url
        self.request_method = "GET"
        self.request_params = {"id": id}

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response
